<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>克隆优化节点</title>
  </head>
  <body>
    <!-- 准备代码 -->
    <p id="box">old</p>
    <script>
      // 1 循环创建 加入节点
      for (var i = 0; i < 3; i++) {
        var oP = document.createElement('p')
        oP.innerHTML = i
        document.body.appendChild(oP)
      }
      // 利用克隆 不是明显的快 但还是快
      var oldP = document.getElementById('box')
      for (var i = 0; i < 3; i++) {
        var newP = oldP.cloneNode(false)
        newP.innerHTML = i
        document.body.appendChild(newP)
      }
    </script>
  </body>
</html>
